package cn.edu.tyu.finance.util;

import java.sql.*;

/**
 * MySQL数据库实用类
 * @author qinying
 * @version 1.0
 */
public class DbUtil {
    public static void main(String[] args){
        DbUtil dbUtil = new DbUtil();
        Connection conn = dbUtil.getConnection();
        System.out.println(conn);
    }
    public static Connection getConnection(){
        Connection conn=null;
        String url="jdbc:mysql://localhost:3306/financedb";
        try {
            conn = DriverManager.getConnection(url, "root", "123123");
        }catch(SQLException e){
            e.printStackTrace();
        }
        return conn;
    }
    /*
    *归还数据库的连接
     */
    public static void backConn(Connection conn, PreparedStatement ps, ResultSet rs){
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(ps!=null){
            try {
                ps.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null){
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
